/**
 * 
 */
package com.lion.jacoco.dao.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.lion.jacoco.dao.AppConfigDAO;
import com.lion.jacoco.dao.dataobject.AppConfigDO;

/**
 * AppConfigDAOImpl.java. 2011-11-26下午10:06:23 @author LionBule.
 */
public class AppConfigDAOImpl extends BaseDAO implements AppConfigDAO {
    private String nameSpace = "AppConfig";

    @Override
    protected String getNameSpace() {
        return nameSpace;
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<AppConfigDO> queryAll() {
        return this.getSqlMapClientTemplate().queryForList(getStatName("queryAll"));
    }

    @Override
    public int add(AppConfigDO data) {
        if (data == null) {
            throw new IllegalArgumentException();
        }
        return (Integer)this.getSqlMapClientTemplate().insert(getStatName("add"), data);
    }

    @Override
    public int updateById(AppConfigDO data) {
        if (data == null || data.getId() <= 0 || StringUtils.isBlank(data.getIp())) {
            throw new IllegalArgumentException();
        }
        return getSqlMapClientTemplate().update(getStatName("updateById"), data);
    }

    @Override
    public int delete(int id) {
        if (id <= 0) {
            throw new IllegalArgumentException();
        }
        return getSqlMapClientTemplate().delete(getStatName("delete"), id);
    }

    @Override
    public AppConfigDO queryById(int id) {
        if (id <= 0) {
            throw new IllegalArgumentException();
        }
        return (AppConfigDO) getSqlMapClientTemplate().queryForObject(getStatName("queryById"), id);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<AppConfigDO> queryByAppName(String name) {
        if (StringUtils.isBlank(name)) {
            throw new IllegalArgumentException();
        }
        return getSqlMapClientTemplate().queryForList(getStatName("queryByAppName"), name);
    }

}
